<template>
  <div class="energy">
    <div class="top-box">
      <div class="title">
        {{title}}
      </div>
      <div>
        <div class="btn-group">
          <span v-for="item in btnList"
                @click="changeDate(item.code)"
                :key="item.code"
                :class="activeBtn==item.code?'selected':''">{{item.label}}</span>
        </div>
      </div>
    </div>
    <div>
      <line-chart height="190px"
                  v-if="type == 'energy'"
                  :chartData="chartData"
                  :timeData="timeData"></line-chart>
      <ElectricityChart height="190px"
                        v-if="type == 'electricity'"
                        :chartData="chartData"
                        :timeData="timeData"></ElectricityChart>
      <CarbonChart height="190px"
                   v-if="type == 'carbon'"
                   :chartData="chartData"
                   :timeData="timeData"></CarbonChart>
    </div>
    <div>
    </div>
  </div>
</template>

<script>
import LineChart from "./charts/lineChart"
import ElectricityChart from "./charts/electricityChart"
import CarbonChart from "./charts/carbonChart"
export default {
  name: 'energy',
  mounted() {
  },
  props: {
    type: {
      default: "energy",
      type: String
    },
    title: {
      default: "",
      type: String
    }
  },
  components: {
    LineChart,
    ElectricityChart,
    CarbonChart
  },
  data() {
    return {
      activeBtn: 'day',
      btnList: [
        {
          label: "近一天",
          code: "day"
        },
        {
          label: "近一周",
          code: "week"
        },
        {
          label: "近一月",
          code: "mounth"
        },
      ],

      chartData: [1, 6, 2, 8, 3, 1],
      timeData: [1, 2, 3, 4, 5, 6]
    }
  },
  methods: {
    changeDate(e) {
      this.activeBtn = e;
    }
  }
}
</script>
<style lang="scss">
.energy {
  width: 100%;
  height: 220px;
  background: #ffffff;
  border-radius: 4px;
  padding: 16px;
  .top-box {
    font-family: "Microsoft YaHei";
    font-style: normal;
    display: flex;
    justify-content: space-between;
    .title {
      font-weight: 700;
      font-size: 16px;
      line-height: 21px;

      color: #000000;
    }
    .btn-group {
      padding: 3px;
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 6px;
      height: 26px;

      background: #f0f2f3;
      /* 05 黑白灰 */

      border: 0.5px solid #e7e8e9;
      border-radius: 2px;
      font-weight: 400;
      font-size: 12px;
      line-height: 16px;
      text-align: center;

      /* 03黑白灰 */
      color: #636e78;
      span {
        width: 45px;
        height: 20px;
        font-size: 12px;
        line-height: 20px;
        cursor: pointer;
      }
      .selected {
        /* 08 黑白灰 */
        background: #ffffff;
        border-radius: 2px;
        font-weight: 700;
        text-align: center;

        /* 04 蓝 */

        color: #1d99ef;
      }
    }
  }
}
</style>
